<template>
  <div class="gedansquare">
    <van-row
      style="font-size: 20px; padding: 20px 10px"
      @click="handleGoDetails"
    >
      <van-col span="8" style="text-align: left"
        ><van-icon name="arrow-left"
      /></van-col>
      <van-col span="8" style="text-align: center">歌单广场</van-col>
      <van-col span="8" style="text-align: right"
        ><van-icon name="share-o"
      /></van-col>
    </van-row>
    <van-row type="flex" justify="space-around">
      <van-col
        span="8"
        v-for="(item, index) in romance"
        :key="index"
        @click="handleSongDetail(item.id)"
      >
        <div class="songList">
          <img :src="item.coverImgUrl" alt="" />
          <p style="line-height: 17px; text-align: left">
            {{ item.name }}
          </p>
          <div class="count">▷{{ parseInt(item.playCount / 10000) }}万</div>
        </div>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import axios from "axios";
import { Col, Row } from "vant";
import { Icon } from "vant";
export default {
  data() {
    return {
      romance: [],
    };
  },
  computed: {},
  watch: {},

  methods: {
    async gedansquare() {
      const result = await axios.get(
        "http://192.168.31.27:3000/playlist/catlist?" + this.param
      );
      // console.log("远离纷扰，歌单分类", result);
      //获取分类的随机数
      const random = Math.floor(
        Math.random() * Math.floor(result.data.sub.length)
      );
      // console.log(random);
      //获取 浪漫 歌单
      const romance = result.data.sub[random].name;
      // console.log(romance);
      //通过分类接口调取歌单
      const res = await axios.get(
        "http://192.168.31.27:3000/top/playlist/highquality?" + this.param,
        {
          params: {
            cat: romance,
          },
        }
      );
      // console.log("通过分类调取歌单", res);
      this.romance = res.data.playlists;
    },
    //点击歌单进入歌单详情
    handleSongDetail(id) {
      this.$router.push("/songlistdetails/" + id);
    },
    handleGoDetails() {
      this.$router.go(-1);
    },
  },
  created() {
    this.gedansquare();
  },
  mounted() {},
  components: {},
};
</script>
<style scoped>
.songList {
  width: 105px;
  margin: 0 auto;
  position: relative;
}
.songList img {
  width: 105px;
  border-radius: 13px;
}
.songList .count {
  width: 55px;
  padding: 0 5px;
  height: 20px;
  text-align: center;
  background: rgb(58, 58, 58);
  opacity: 0.8;
  line-height: 20px;
  border-radius: 20px;
  color: #fff;
  position: absolute;
  top: 4px;
  right: 4px;
}
</style>
